/*
	libsimple_geom - a geometric library that wants to be
	https://notabug.org/namark/libsimple_geom
	https://gitlab.com/namark/libsimple_geom
	https://github.com/namark/libsimple_geom

	Copyright (C) 2017-2019 respective authors/contributors

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SIMPLE_GEOM_BOX_HPP
#define SIMPLE_GEOM_BOX_HPP

#include "vector.hpp"
#include "simple/support/range.hpp"

namespace simple::geom
{

	template <typename Type>
	struct segment
	{
		Type size, position;

		using range = support::range<Type>;

		constexpr operator range() const
		{
			return range{position, position + size};
		}
	};

	template <typename Type, typename AnchorType = Type>
	struct anchored_segment : public segment<Type>
	{
		using base = segment<Type>;
		AnchorType anchor;

		constexpr anchored_segment() = default;

		constexpr operator typename base::range() const
		{
			auto lower = this->position -
				static_cast<Type>(anchor * static_cast<AnchorType>(this->size));
			return typename base::range{lower, lower + this->size};
		}

	};

	template <typename Coordinate, size_t Dimensions = 2>
	using vector_segment = segment<vector<Coordinate, Dimensions>>;

	template <typename Coordinate, size_t Dimensions = 2, typename Anchor = Coordinate>
	using anchored_vector_segment = anchored_segment<vector<Coordinate, Dimensions>, vector<Anchor, Dimensions>>;

} // namespace simple::geom

#endif /* end of include guard */
